package com.issac.springbootredis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class RedisController {

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @GetMapping("/set/{key}")
    public void set(@PathVariable("key") String key){
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        ops.set(key, UUID.randomUUID().toString());
    }
    @GetMapping("/get/{key}")
    public String get(@PathVariable("key") String key){
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        return ops.get(key);
    }
}
